//package com.ita.aspect;
//
//import java.lang.annotation.Annotation;
//import java.lang.reflect.Method;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpSession;
//
package com.ita.aspect;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

//import oracle.net.aso.l;
//
//
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.annotation.AfterThrowing;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Before;
//import org.aspectj.lang.annotation.Pointcut;
//import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import com.ita.annotation.*;
//import com.ita.log.Log;
//import com.ita.pojo.MUser;
//import com.ita.util.Constant;
//import com.ita.util.JacksonUtil;
//import com.ita.util.TimeUtil;
//
//@Component
//@Aspect
//public class LogAspect {
//
//	private static final Logger logger = Logger.getLogger(LogAspect.class);
//
//	@Pointcut("@annotation(com.ita.annotation.ServiceLog)")
//	public void serviceAspect() {
//
//	}
//
//	@Pointcut("@annotation(com.ita.annotation.ControllerLog)")
//	public void controllerAspect() {
//	}
//
//	@Before("controllerAspect()")
//	public void doBefore(JoinPoint joinPoint) {
//		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
//				.getRequest();
//		HttpSession session = request.getSession();
//
//		MUser merchant = (MUser) session.getAttribute(Constant.CURRENT_MERCHANT);
//		String ip = request.getRemoteAddr();
//		try {
//
//			Log log = new Log();
//			log.setDescription(getMthodDescription(joinPoint, ControllerLog.class));
//			log.setMethod(
//					(joinPoint.getTarget().getClass().getName() + "." + joinPoint.getSignature().getName() + "()"));
//			log.setType("0");
//			log.setRequestIp(ip);
//			log.setExceptionCode(null);
//			log.setExceptionDetail(null);
//			log.setParams(null);
//			log.setMerchant(merchant);
//			log.setDate(TimeUtil.getCurrentDate());
//
//			logger.info(log);
//		} catch (Exception e) {
//			logger.error(e.getMessage());
//		}
//	}
//
//	@AfterThrowing(pointcut = "serviceAspect()", throwing = "e")
//	public void doAfterThrowing(JoinPoint joinPoint, Throwable e) {
//		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
//				.getRequest();
//		HttpSession session = request.getSession();
//		MUser merchant = (MUser) session.getAttribute(Constant.CURRENT_MERCHANT);
//		String ip = request.getRemoteAddr();
//		String params = "";
//		if (joinPoint.getArgs() != null && joinPoint.getArgs().length > 0) {
//			for (int i = 0; i < joinPoint.getArgs().length; i++) {
//				params += JacksonUtil.getJsonFromObject(joinPoint.getArgs()[i]) + ";";
//			}
//		}
//		try {
//
//			Log log = new Log();
//			log.setDescription(getMthodDescription(joinPoint, ServiceLog.class));
//			log.setExceptionCode(e.getClass().getName());
//			log.setType("1");
//			log.setExceptionDetail(e.getMessage());
//			log.setMethod(
//					(joinPoint.getTarget().getClass().getName() + "." + joinPoint.getSignature().getName() + "()"));
//			log.setParams(params);
//			log.setMerchant(merchant);
//			log.setDate(TimeUtil.getCurrentDate());
//			log.setRequestIp(ip);
//
//			logger.info(log);
//
//		} catch (Exception ex) {
//			logger.error(ex.getMessage());
//		}
//
//	}
//
//	public static <T extends Annotation> String getMthodDescription(JoinPoint joinPoint, Class<T> annotationClass)
//			throws Exception {
//		String targetName = joinPoint.getTarget().getClass().getName();
//		String methodName = joinPoint.getSignature().getName();
//		Object[] arguments = joinPoint.getArgs();
//		Class targetClass = Class.forName(targetName);
//		Method[] methods = targetClass.getMethods();
//		String description = "";
//		for (Method method : methods) {
//			if (method.getName().equals(methodName)) {
//				Class[] clazzs = method.getParameterTypes();
//				if (clazzs.length == arguments.length) {
//					description = ((ControllerLog) method.getAnnotation(annotationClass)).description();
//					break;
//				}
//			}
//		}
//		return description;
//	}
//
//}
